package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;

/**
 * @author ZYJ
 * 
 *         车辆调度
 */
@Entity
@Table(name = "bd_cardispatch")
@Indexed
@CriteriaEnhancers(criteriaEnhancers = {
		@CriteriaEnhancer(impl = OrderCriteriaEnhancer.class, parameter = "dispatchDate") })
public class CarDispatchBill extends BaseModel {

	private static final long serialVersionUID = 3952715762097430855L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@DocumentId
	private Long pkCarDispatchBill;

	/** 组团预约 */
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
	@JoinColumn(name = "pkGroupReserve")
	@IndexedEmbedded(depth = 1)
	private GroupReserve groupReserve;

	/** 散客团预约 */
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
	@JoinColumn(name = "pkNonMemGroupReserve")
	@IndexedEmbedded(depth = 1)
	private NonMemGroupReserve nonMemGroupReserve;

	/** 单号 */
	@Column
	@Field
	private String oddCode;

	/** 是否为本单位车 */
	@Column
	@Field
	private Boolean unitsCar;

	/** 公司名称 当不是单位车时，填写公司名称 */
	@Column
	@Field
	private String companyName;

	/** 车辆型号 当不是单位车时，填写外公司车的型号 */
	@Column
	@Field
	private String carModel;

	/** 司机姓名 车辆型号 当不是单位车时，填写外公司的司机 */
	@Column
	@Field
	private String driverName;

	/** 司机电话 */
	@Column
	@Field
	private String driverPhone;

	/** 车辆 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkCar")
	private Car car;

	/** 司机 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkDriver")
	private Driver driver;

	/** 用车时间 */
	@Column
	private Date dispatchDate;

	/** 收车时间 */
	@Column
	private Date backDate;

	/** 派车地址 */
	@Column
	@Field
	private String address;

	/** 总费用 */
	@Column
	@Field
	private Double totalPrice;

	/** 备注 */
	@Column(length = 1023)
	private String description;

	/** 状态 */
	@Enumerated(EnumType.STRING)
	@Field
	@In
	@FieldBridge(impl = EnumBridge.class)
	private CarStatus carStatus;

	@Version
	private Integer version;

	@JsonSerialize(using = EnumSerializer.class)
	public static enum CarStatus {
		Initial("初始"), Sent("已派车"), Back("已收车");

		private String display;

		CarStatus(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	public Long getPkCarDispatchBill() {
		return pkCarDispatchBill;
	}

	public void setPkCarDispatchBill(Long pkCarDispatchBill) {
		this.pkCarDispatchBill = pkCarDispatchBill;
	}

	public GroupReserve getGroupReserve() {
		return groupReserve;
	}

	public void setGroupReserve(GroupReserve groupReserve) {
		this.groupReserve = groupReserve;
	}

	public NonMemGroupReserve getNonMemGroupReserve() {
		return nonMemGroupReserve;
	}

	public void setNonMemGroupReserve(NonMemGroupReserve nonMemGroupReserve) {
		this.nonMemGroupReserve = nonMemGroupReserve;
	}

	public String getOddCode() {
		return oddCode;
	}

	public void setOddCode(String oddCode) {
		this.oddCode = oddCode;
	}

	public Boolean getUnitsCar() {
		return unitsCar;
	}

	public void setUnitsCar(Boolean unitsCar) {
		this.unitsCar = unitsCar;
	}

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public String getCarModel() {
		return carModel;
	}

	public void setCarModel(String carModel) {
		this.carModel = carModel;
	}

	public String getDriverName() {
		return driverName;
	}

	public void setDriverName(String driverName) {
		this.driverName = driverName;
	}

	public String getDriverPhone() {
		return driverPhone;
	}

	public void setDriverPhone(String driverPhone) {
		this.driverPhone = driverPhone;
	}

	public Car getCar() {
		return car;
	}

	public void setCar(Car car) {
		this.car = car;
	}

	public Driver getDriver() {
		return driver;
	}

	public void setDriver(Driver driver) {
		this.driver = driver;
	}

	public Date getDispatchDate() {
		return dispatchDate;
	}

	public void setDispatchDate(Date dispatchDate) {
		this.dispatchDate = dispatchDate;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Double getTotalPrice() {
		return totalPrice;
	}

	public void setTotalPrice(Double totalPrice) {
		this.totalPrice = totalPrice;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public Date getBackDate() {
		return backDate;
	}

	public void setBackDate(Date backDate) {
		this.backDate = backDate;
	}

	public CarStatus getCarStatus() {
		return carStatus;
	}

	public void setCarStatus(CarStatus carStatus) {
		this.carStatus = carStatus;
	}

}
